package com.demo.generic;

import java.util.LinkedList;
import java.util.List;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-11 7:32
 * @Description: GenericDemo$
 */
public class GenericDemo {

	public static void handleNumber(GenericClassDemo<Integer> integerGenericClass){
		Integer result = 111 + integerGenericClass.getMember();
		System.out.println("result is "+result);
	}

	public static void main(String[] args) {
		//beforeGeneric();
		//afterGeneric();
		GenericClassDemo<String> stringGenericClass = new GenericClassDemo<>("generic class");
		GenericClassDemo<Integer> integerGenericClass = new GenericClassDemo<>(1);

		System.out.println(stringGenericClass.getMember().getClass());
		System.out.println(integerGenericClass.getMember().getClass());
		stringGenericClass.handleSomething("generic class");
		integerGenericClass.normalMethod("Tom");
		handleNumber(integerGenericClass);

		Integer[] integers = new Integer[]{1,2,3,4,5};
		Double[] doubles = new Double[]{1.1,2.2,3.3,4.4,5.5};
		Character[] characters = new Character[]{'A','B','C','D','E'};

		stringGenericClass.printArray(integers);
		stringGenericClass.printArray(doubles);
		stringGenericClass.printArray(characters);

		stringGenericClass.printArray2(integers);
		stringGenericClass.printArray2(doubles);
		stringGenericClass.printArray2(characters);
	}

	private static void afterGeneric() {
		List<String> linkedList = new LinkedList<>();
		linkedList.add("demo");
		//linkedList.add(1);

		for (int i = 0; i < linkedList.size(); i++) {
			String item = (String) linkedList.get(i);
			System.out.println(item);
		}
	}

	private static void beforeGeneric() {
		List linkedList = new LinkedList<>();
		linkedList.add("demo");
		linkedList.add(1);

		for (int i = 0; i < linkedList.size(); i++) {
			String item = (String) linkedList.get(i);
			System.out.println(item);
		}
	}
}
